<!DOCTYPE html>
<html xmlns:layout="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
	layout:decorate="~{common/layoutAdmin}">

<head>
	<meta charset="UTF-8">
	<title>用户信息</title>
</head>

<body>
	<div layout:fragment="fragment_body">
		<el-row :gutter="20">
			<el-col :span="24">
				<el-button type="primary" @click="openRaceAccount(null)" v-show="raceAccountForm.accountType == 2" >新增</el-button>
				<el-table :data="raceAccounts" border highlight-current-row style="width: 100%">
					<!-- -->
					<!--<el-table-column prop="accountUser" label="登陆账号"></el-table-column>-->
					<el-table-column prop="accountNumber" :label="accNumber"></el-table-column>
					<!--<el-table-column prop="accountPassword" label="登陆密码"></el-table-column>-->
					<el-table-column prop="accountName" label="姓名"></el-table-column>
					<el-table-column prop="accountOpenId" label="微信绑定">
						<template slot-scope="scope">
							{{scope.row.accountOpenId == null?'未绑定':'已绑定'}}
						</template>
					</el-table-column>
					<el-table-column prop="accountNick" label="昵称"></el-table-column>
					<el-table-column prop="accountLogo" label="头像">
						<template slot-scope="scope">
							<img v-if="scope.row.accountLogo" :src="scope.row.accountLogo" class="avatar-sm">
						</template>
					</el-table-column>
					<el-table-column prop="accountStatus" label="状态">
						<template slot-scope="scope">
						{{['未激活','有效','不可登录'][scope.row.accountStatus]}}
						</template>
					</el-table-column>
					<!--<el-table-column prop="accountType" label="0无效，1学生，2教师，3团委"></el-table-column>-->
					<el-table-column prop="accountTime" label="创建时间"></el-table-column>
					<el-table-column label="操作" width="160px">
						<template slot-scope="scope">
							<el-button @click="openRaceAccount(scope.row)" type="text" size="small">修 改</el-button>
							<el-popconfirm title="是否删除？" @confirm="delRaceAccount(scope.row.accountId)">
								<el-button slot="reference" type="text" size="small">删 除</el-button>
							</el-popconfirm>
						</template>
					</el-table-column>
				</el-table>
			</el-col>
		</el-row>
		<!--弹框-->
		<el-dialog :title="raceAccountForm.ttitle" :visible.sync="raceAccountForm.visible" width="30%">
			<el-form :model="raceAccountForm" :rules="raceAccountRules" ref="raceAccountForm" label-width="100px">
				<!-- -->
				<!--<el-form-item label="登陆账号" prop="accountUser">
					<el-input v-model="raceAccountForm.accountUser"></el-input>
				</el-form-item>-->
				<el-form-item :label="accNumber" prop="accountNumber">
					<el-input v-model="raceAccountForm.accountNumber"></el-input>
				</el-form-item>
				<el-form-item label="姓名" prop="accountName">
					<el-input v-model="raceAccountForm.accountName"></el-input>
				</el-form-item>
				<!--<el-form-item label="微信openid" prop="accountOpenId">
					<el-input v-model="raceAccountForm.accountOpenId"></el-input>
				</el-form-item>-->
				<el-form-item label="昵称" prop="accountNick">
					<el-input v-model="raceAccountForm.accountNick"></el-input>
				</el-form-item>
				<el-form-item label="登陆密码" prop="accountPassword" >
					<el-input v-model="raceAccountForm.accountPassword"></el-input>
					<!--<small>输入密码才会修改密码</small>-->
				</el-form-item>
				<!--<el-form-item label="头像" prop="accountLogo">
					<el-input v-model="raceAccountForm.accountLogo"></el-input>
				</el-form-item>-->
				<!--<el-form-item label="0未激活，1有效，2不可登录" prop="accountStatus">
					<el-input v-model="raceAccountForm.accountStatus"></el-input>
				</el-form-item>-->
				<!--<el-form-item label="0无效，1学生，2教师，3团委" prop="accountType">
					<el-input v-model="raceAccountForm.accountType"></el-input>
				</el-form-item>-->
				<!--<el-form-item label="创建时间" prop="accountTime">
					<el-input v-model="raceAccountForm.accountTime"></el-input>
				</el-form-item>-->
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="closeRaceAccount">取 消</el-button>
				<el-button type="primary" @click="saveRaceAccount">保 存</el-button>
			</span>
		</el-dialog>
	</div>
</body>
<script type="text/javascript" layout:fragment="fragment_script">
	let vueData = {
		raceAccounts: [],
		selectRaceAccount: null,
		accNumber: '工号',
		raceAccountForm: {
			visible: false,
			ttitle: '创建账号/修改',
			accountId : '',
			accountUser : '',
			accountPassword : '',
			accountName : '',
			accountNumber : '',
			accountOpenId : '',
			accountNick : '',
			accountLogo : '',
			accountStatus : '',
			accountType : '',
			accountTime : '',
		},
		raceAccountQuery: {
			userId: 'not',
			type: 'not',
			page: '',
			size: '',
		},
		raceAccountRules: {
			accountId: [
				{required: false, message: '不能为空', trigger: 'blur'}
			],
			accountUser: [
				{required: false, message: '不能为空', trigger: 'blur'}
			],
			accountPassword: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			accountName: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			accountNumber: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			accountOpenId: [
				{required: false, message: '不能为空', trigger: 'blur'}
			],
			accountNick: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			accountLogo: [
				{required: false, message: '不能为空', trigger: 'blur'}
			],
			accountStatus: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			accountType: [
				{required: false, message: '不能为空', trigger: 'blur'}
			],
			accountTime: [
				{required: false, message: '不能为空', trigger: 'blur'}
			],
		},
	}
	let vueMethods = {
		getRaceAccounts() {
			let that = this
			postRequst('/user/getAccounts', that.raceAccountQuery, true).then(function (resp) {
				that.raceAccounts = resp.rows
				if (resp.rows && resp.rows.length > 0) {
					that.selectRaceAccount = resp.rows[0]
				}
			})
		},
		openRaceAccount(row) {
			let that = this
			if (row) {
				that.raceAccountForm.ttitle = '修改'
				that.raceAccountForm.accountId = row.accountId
				that.raceAccountForm.accountUser = row.accountUser
				that.raceAccountForm.accountPassword = row.accountPassword
				that.raceAccountForm.accountName = row.accountName
				that.raceAccountForm.accountNumber = row.accountNumber
				that.raceAccountForm.accountOpenId = row.accountOpenId
				that.raceAccountForm.accountNick = row.accountNick
				that.raceAccountForm.accountLogo = row.accountLogo
				that.raceAccountForm.accountStatus = row.accountStatus
				that.raceAccountForm.accountType = row.accountType
				//that.raceAccountForm.accountTime = row.accountTime
			} else {
				that.raceAccountForm.ttitle = '新增'
				that.raceAccountForm.accountId = ''
				that.raceAccountForm.accountUser = ''
				that.raceAccountForm.accountPassword = ''
				that.raceAccountForm.accountName = ''
				that.raceAccountForm.accountNumber = ''
				that.raceAccountForm.accountOpenId = ''
				that.raceAccountForm.accountNick = ''
				that.raceAccountForm.accountLogo = ''
				that.raceAccountForm.accountStatus = ''
				//that.raceAccountForm.accountType = ''
				that.raceAccountForm.accountTime = ''
			}
			that.raceAccountForm.visible = true
		},
		closeRaceAccount() {
			this.$refs["raceAccountForm"].resetFields();
			this.raceAccountForm.visible = false
		},
		saveRaceAccount() {
			let that = this
			this.$refs["raceAccountForm"].validate((valid) => {
				if (valid) {
					var url = '/user/createAccount'
					if(that.raceAccountForm.accountId){
						url = '/admin/updateAccount'
					}
					postRequst(url, that.raceAccountForm).then(function (resp) {
						if (resp.status == 0) {
							that.getRaceAccounts()
							that.raceAccountForm.visible = false
							that.$message({message: resp.msg, type: "success"});
						} else {
							that.$message({message: resp.msg, type: "error"});
						}
					})
				}
			});
		},
		delRaceAccount(accountId) {
			let that = this
			postRequst('/admin/delRaceAccount', {accountId: accountId}, true).then(function (resp) {
				if (resp.status == 0) {
					that.getRaceAccounts()
					that.$message({message: resp.msg, type: "success"});
				} else {
					that.$message({message: resp.msg, type: "error"});
				}
			})
		},
	}
	function vueCreated() {
		let that = this
		var url = window.location.pathname;
		if(url.indexOf('student') >= 0){
			that.accNumber = '学号'
			that.raceAccountForm.accountType = 0
			that.raceAccountQuery.type = 0
		}else if(url.indexOf('teacher') >= 0){
			that.raceAccountForm.accountType = 1
			that.raceAccountQuery.type = 1
		}else{
			that.raceAccountForm.accountType = 2
			that.raceAccountQuery.type = 2
		}
		that.getRaceAccounts()
	}
</script>

</html>